<template>
  <div ref="container" class="Business text-white">
    <div v-if="productInfo" class="content-view">
      <div class="top-view">
        <div class="tag">{{ productInfo.TypeName }}</div>
        <div class="title">
          {{ productInfo.TitleA }}
        </div>
        <div class="desc">
          {{ productInfo.IntroduceA }}
        </div>
      </div>
      <div class="card-text-view">
        <div class="card-item img" :style="contentStyle">
          <img :src="productInfo.LargePicA" alt="" />
        </div>
        <div class="card-item img" :style="contentStyle">
          <img :src="productInfo.LargePicB" alt="" />
        </div>
      </div>
      <div class="center-view">
        <div class="title">{{ productInfo.TitleB }}</div>
        <div class="desc">
          {{ productInfo.IntroduceB }}
        </div>
      </div>
      <div class="card-text-view" style="padding: 0 18%">
        <div class="card-item textr" :style="{ width: contentStyle.width }">
          <div class="title">{{ productInfo.TitleC }}</div>
          <div class="desc">
            {{ productInfo.IntroduceC }}
          </div>
        </div>
        <div class="card-item img" :style="{ width: contentStyle.width }">
          <img class="cotiner" :src="productInfo.LargePicC" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import { GetSleepDetail } from "@/server";
import { useAppStore } from "@/store/modules/user";
const route = useRoute();
const id = computed(() => route.params.id);
const store = useAppStore();
const container = ref<HTMLElement | null>(null);
const contentStyle = ref({ width: "844px", height: "50%" });
const handleResize: ResizeObserverCallback = (entries) => {
  if (entries[0].target) {
    const containerWidth = entries[0].contentRect.width;
    const w = (containerWidth - containerWidth * 0.12) / 2;
    contentStyle.value = { width: w + "px", height: w + "px" };
  }
};
const productInfo = ref(null) as any;
const GetSleepDetailFun = async () => {
  const res: any = await GetSleepDetail({
    Id: id.value,
  });
  if (res.Tag === 1) {
    productInfo.value = res.Data;
  } else {
    store.error(res.Message); // 错误提示
  }
};
GetSleepDetailFun();
onMounted(() => {
  const resizeObserver = new ResizeObserver(handleResize);
  if (container.value) {
    resizeObserver.observe(container.value);
  }

  return () => {
    if (container.value) {
      resizeObserver.unobserve(container.value);
    }
    resizeObserver.disconnect();
  };
});
</script>
<style lang="less" scoped>
.Business {
  width: 100%;
  min-height: 100%;
  padding-bottom: 40px;
  background: #ffffff;
  .content-view {
    position: relative;
    .top-view {
      width: 40%;
      margin: 60px auto;
      text-align: left;
      .tag {
        font-size: 14px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #000000;
        margin-bottom: 7px;
      }
      .title {
        font-size: 30px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        color: #000000;
        margin-bottom: 45px;
      }
      .desc {
        font-size: 15px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #000000;
        line-height: 28px;
        padding-bottom: 40px;
        white-space: pre-wrap;
      }
    }
    .center-view {
      width: 40%;
      margin: 70px auto;
      text-align: left;
      .title {
        font-size: 22px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        color: #000000;
        line-height: 37px;
        margin-bottom: 22px;
      }
      .desc {
        font-size: 15px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        color: #000000;
        line-height: 27px;
        padding-bottom: 50px;
        white-space: pre-wrap;
      }
    }
    &.no {
      user-select: none;
      opacity: 0.2;
    }
    margin-top: 30px;
    .card-text-view {
      display: flex;
      justify-content: center;
      // margin-bottom: 74px;
      .card-item {
        position: relative;
        width: 50%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: flex-start;
        img {
          &.cotiner {
            object-fit: contain;
            height: auto;
          }
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
        &.text {
          padding: 0 5% 0 8%;
        }
        &.textr {
          padding: 0 8% 0 5%;
        }
        .title {
          text-align: left;
          font-size: 22px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          color: #000000;
          line-height: 27px;
          margin-bottom: 25px;
        }
        .line {
          width: 96px;
          height: 4px;
          background: #f3f3f3;
          margin: 26px 0 20px;
        }
        .desc {
          white-space: pre-wrap;
          text-align: left;
          font-size: 15px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #000000;
          line-height: 27px;
        }
      }
    }
  }
}
input {
  &.num {
    text-align: center;
    width: 30px;
    margin-left: 5px;
  }
  height: 26px;
}
.copper-view {
  width: 100vw;
  height: 100vh;
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.7);
}
</style>
